from read.readCsv import ReadCsv
from read.readExcel import ReadExcel
import requests


class ReqeustCsv():

    def requestCsv(self):
        r = ReadCsv()
        re = ReadExcel()
        # [['https://www.wanandroid.com/article/query/0/json', '{"k":"android"}', 'post'],
        # ['https://www.wanandroid.com/project/list/1/json', '{"cid":"294"}', 'get']]
        datas = r.readCsv("../data/data.csv")
        datas = re.readExcel("C:\\Users\\apple\\Desktop\\url.xlsx")
        print(datas)

        #将状态码存起来
        statusCodes = []

        for data in datas:
            # ['https://www.wanandroid.com/article/query/0/json', '{"k":"android"}', 'post'],
            # '{"k":"android"}' 变成字典 {"k":"android"}
            params = eval(data[1])
            # params = data[1]
            if data[2] == "get":
                # get请求
                r = requests.get(data[0],params=params)
                print(r.text)
                statusCodes.append(r.status_code)
            elif data[2] == "post":
                # post请求,data参数必须是字典，'{"k":"android"}'这个不行
                r = requests.post(data[0],data=params)
                print(r.text)
                statusCodes.append(r.status_code)

        return statusCodes

ReqeustCsv().requestCsv()